#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<queue>
#include<vector>
using namespace std;
 // Definition for a binary tree node.
  struct TreeNode {
      int val;
      TreeNode *left;
      TreeNode *right;
      TreeNode(int x) : val(x), left(NULL), right(NULL) {}
  };
 
class Solution {
public:
    vector<int> levelOrder(TreeNode* root) {
        if (root == nullptr)
        {
            return {};
        }
        vector<int> ans;
        queue<TreeNode*> q;
        q.push(root);
        while (!q.empty())
        {
            TreeNode* front = q.front();
            ans.push_back(front->val);
            q.pop();

            if (front->left)
            {
                q.push(front->left);
            }
            if (front->right)
            {
                q.push(front->right);
            }
        }
        return ans;
    }
};